package tdh.xt.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tdh.xt.dao.DepartDao;
import tdh.xt.entity.po.Depart;
import tdh.xt.service.DepartService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("departService")
public class DepartServiceImpl implements DepartService {

    @Resource(name = "departDao")
    DepartDao departDao;

    @Transactional(transactionManager = "transactionManager", rollbackFor = {Exception.class})
    @Override
    public List<Depart> getAllDepart() {
        return departDao.getAllDepart();
    }

    @Transactional(transactionManager = "transactionManager", rollbackFor = {Exception.class})
    @Override
    public Map<String, String> getDepartCodeAndName() {
        List<Depart> allDepart = getAllDepart();
        Map<String, String> map = new HashMap<String, String>();
        for (Depart depart : allDepart) {
            map.put(depart.getBmdm(), depart.getBmmc());
        }
        return map;
    }
}
